package strategy

import (
	"fmt"
	"github.com/Exleryz/gorequest"
	"github.com/Exleryz/m3u8/util"
)

type M3U8KeyOpt interface {
	GetKeyBytes(uri string) ([]byte, error)
}

// 接口约束
var _ = M3U8KeyOpt(DefaultKeyDownload{})

// DefaultKeyDownload 这里填一个默认实现
type DefaultKeyDownload struct {
}

func (receiver DefaultKeyDownload) GetKeyBytes(uri string) ([]byte, error) {
	// 没有鉴权直接下载
	_, data, errors := util.NewRequest(gorequest.New().Get(uri)).
		EndBytes()
	if errors != nil && len(errors) > 0 {
		fmt.Println(errors)
		return nil, errors[0]
	}
	return data, nil
}
